#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QPainter>
#include <QTimer>
#include <qevent.h>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    x=y=m=0;
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent *e)
{
    QPainter painter;
    painter.begin(this);
    painter.setPen(Qt::blue);
    painter.setFont(QFont("Arial", 30));
    painter.drawText(rect(), Qt::AlignCenter, "Qt");

    painter.drawEllipse(x,y,200,200);

    painter.drawText(QRect(m,0,this->width(),60),Qt::AlignCenter,"今天星期六大家还在努力学习");
    painter.drawText(QRect(m-this->width(),0,this->width(),60),Qt::AlignCenter,"今天星期六大家还在努力学习");
    if(m==this->width())m=0;
    painter.end();

    QTimer *timer = new QTimer();
    timer->setInterval(1000);
    QObject::connect(timer, SIGNAL(timeout()), [=](){
        m++;
    });
    timer->start();
//    m++;
    update();
}

void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
    x=e->pos().x();
    y=e->pos().y();
    update();
}




